﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using XNADota.Graphics;
using JigLibX.Physics;
using XNADota.MDX;
using JigLibX.Geometry;
using JigLibX.Collision;
using JiggleGame.PhysicObjects;
using System.Diagnostics;
using JigLibX.Math;

namespace XNADota.GamePlay
{
    public class BasicObject : UnitInstance
    {
        protected string _Id;
        protected EObjectType _ObjectType;

        public BasicObject(string Id, EObjectType objectType)
            : base(Vector3.Zero, Vector3.One, new Vector3(-(float)Math.PI / 2, -(float)Math.PI / 2.0f, 0), ERenderState.None, BasicObject.GetUnitRenderer(Id))
        {
            _Id = Id;
            _ObjectType = objectType;
            IsSelected = false;
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        public static UnitRenderer GetUnitRenderer(string Id)
        {
            PaletteRendererManager manager = SceneManager.Instance.PaletteRendererManager;

            // insert palette render
            if (manager.GetPaletteRenderer(EPaletteRendererType.Unit, Id) == null)
            {
                string path = GameplayWorld.Instance.ObjectsManager.GetFiledValue(EObjectType.UnitData, Id, "file");
                (manager[EPaletteRendererType.Unit] as UnitPaletteRenderContainer).AddUnitRenderer(Id, path, XNADota.Instance);
            }

            return (manager.GetPaletteRenderer(EPaletteRendererType.Unit, Id) as UnitRenderer);
        }

        #region Helper to get values
        public int GetInt(string intString)
        {
            if (intString == null)
                return 0;

            return int.Parse(intString);
        }

        public bool GetBool(string boolString)
        {
            return Convert.ToBoolean(int.Parse(boolString));
        }

        public float GetFloat(string floatString)
        {
            float value;
            float.TryParse(floatString, out value);
            return value;
        }
        #endregion
    }
}
